package com.yxinsur.imc.business.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;

import com.yxinsur.imc.business.domain.ImcIns;
import com.yxinsur.imc.business.form.AssessmentForm;
import com.yxinsur.imc.business.vo.AssessmentVo;
import com.yxinsur.imc.common.utils.DateUtils;
import com.yxinsur.imc.common.utils.SecurityUtils;
import com.yxinsur.imc.common.validator.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yxinsur.imc.business.mapper.ImcAssessmentMapper;
import com.yxinsur.imc.business.domain.ImcAssessment;
import com.yxinsur.imc.business.service.IImcAssessmentService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 考核主Service业务层处理
 * 
 * @author imc
 * @date 2021-06-10
 */
@Service
public class ImcAssessmentServiceImpl extends ServiceImpl<ImcAssessmentMapper, ImcAssessment> implements IImcAssessmentService
{
    private static final Logger logger = LoggerFactory.getLogger(ImcAssessmentServiceImpl.class);
    @Autowired
    private ImcAssessmentMapper imcAssessmentMapper;

    /**
     * 查询考核主列表
     * 
     * @param assessmentForm 考核主
     * @return 考核主
     */
    @Override
    public List<AssessmentVo> selectImcAssessmentList(AssessmentForm assessmentForm)
    {
        return imcAssessmentMapper.selectImcAssessmentList(assessmentForm, SecurityUtils.getTenantId());
    }

    /**
     * 执行考核
     *
     * @param assessmentForm 考核主
     * @return 结果
     */
    @Override
    @Transactional
    public int excuteAssessment(AssessmentForm assessmentForm) {
        Assert.isBlank(assessmentForm.getAssMonth(),"考核月度为必选");
        Assert.isNull(assessmentForm.getOrgId(),"考核机构为必选");
        Assert.isNull(assessmentForm.getMetaId(),"考核元数据为必选");
        
        return 0;
    }

    /**
     * 批量删除考核主
     * 
     * @param ids 需要删除的考核主ID
     * @return 结果
     */
    @Override
    public int deleteImcAssessmentByIds(Long[] ids)
    {
        logger.info("批量删除考核数据操作：{}",ids);
        int count = 0;
        for(Long id:ids){
            ImcAssessment assessment = this.imcAssessmentMapper.selectById(id);
            assessment.setIsDeleted(assessment.getId());
            assessment.setUpdateId(SecurityUtils.getUsername());
            assessment.setUpdateTime(DateUtils.getNowDate());
            count += this.imcAssessmentMapper.updateById(assessment);
        }
        return count;
    }
}
